#pragma once
#ifndef NALU_H
#define NALU_H
#include <cstdint>

// NALU = NALHeader + payload
struct NalHeader
{
    enum PicCodedType
    {
        B_FRAME = 0b00,
        P_FRAME = 0b01,
        I_FRAME = 0b11,
    };
    enum class NalUnitType : uint8_t
    {
        NAL_UNKNOW = 0,
        NAL_SLICE = 1,
        NAL_SLICE_DPA = 2,
        NAL_SLICE_DPB = 3,
        NAL_SLICE_DPC = 4,
        NAL_SLICE_IDR = 5,
        NAL_SEI = 6,
        NAL_SPS = 7,
        NAL_PPS = 8,
        // NAL_AUD = 9,
        // NAL_EOSEQ = 10,
        // NAL_EOSTREAM = 11,
        // NAL_FILLER = 12,
        // 13-23 保留
        NAL_STAP_A = 24,
        NAL_STAP_B = 25,
        NAL_MTAP16 = 26,
        NAL_MTAP24 = 27,
        NAL_FU_A = 28,
        NAL_FU_B = 29,
        // 30-31 保留
    };
    uint8_t type : 5; // NAL单元类型, 1-23: 单个NAL单元; 24: STAP-A; 25: STAP-B; 26: MTAP16; 27: MTAP24; 28: FU-A; 29: FU-B; 30-31: 保留
    uint8_t nri : 2;  // 0:不重要的数据，1:重要的数据，2:重要的数据，3:重要的数据; 越大越重要
    uint8_t f : 1;    // 禁止位, 当f=1时，表示该NAL单元的结束与下一个NAL单元的开始之间不期望有比特填充。

    PicCodedType getPicCodedType() const { return (PicCodedType)nri; }
};

// FU_A = NalHeader + FUHeader + payload
struct FUHeader
{
    uint8_t type : 5;         // NAL单元类型, 同NalHeader
    uint8_t reserved_bit : 1; // Reserved bit
    uint8_t end_bit : 1;      // End bit of FU; 0: Not the last fragment; 1: Last fragment
    uint8_t start_bit : 1;    // Start bit of FU; 0: Not the first fragment; 1: First fragment
};
#endif